package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.pojo.vo.CompanyInfoVO;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.service.CompanyInfoService;
import com.xbongbong.sys.domain.entity.CompanyEntity;
import com.xbongbong.sys.model.CompanyModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 获取公司信息
 * @author 李少杰
 * @version v1.0.0
 * @date 2022/3/3 23:13
 */
@Service("companyInfoService")
public class CompanyInfoServiceImpl implements CompanyInfoService {
    @Resource
    private CompanyModel companyModel;

    @Override
    public CompanyInfoVO getCompanyInfo(BaseDTO baseDTO) throws XbbException {

        CompanyInfoVO companyInfoVO = new CompanyInfoVO();

        String corpid = baseDTO.getCorpid();
        CompanyEntity companyEntity = companyModel.getByKey(corpid);
        if (Objects.isNull(companyEntity)) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100011);
        }

        companyInfoVO.setCorpid(corpid);
        companyInfoVO.setFeeName(companyEntity.getFeeName());
        companyInfoVO.setCorpName(companyEntity.getCorpName());
        companyInfoVO.setFeeType(companyEntity.getFeeType());
        companyInfoVO.setFeeUserNum(companyEntity.getFeeUserNum());
        companyInfoVO.setIndustry(companyEntity.getIndustry());
        companyInfoVO.setUserNum(companyEntity.getUserNum());

        return companyInfoVO;
    }
}
